package com.hm.cms.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hm.cms.mongo.vo.CmsSeoOptimizeVo;
import com.hm.cms.share.service.CmsSeoOptimizeService;
import com.hm.cms.util.CmsConfigDef;
import com.hm.cms.web.su.BaseController;
import com.hm.common.annotation.AuthenticationAnnotation;
import com.hm.common.annotation.RequestPlanAnnotation;
import com.hm.common.common.CommonUtil;
import com.hm.common.model.ControllerResult;
import com.hm.common.model.PageInfo;
import com.hm.common.util.CommonDef.OperationStatus;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @author shishun.wang
 * @date 下午5:51:26 2016年8月5日
 * @version 1.0
 * @describe
 */
@ResponseBody
@RestController
@RequestMapping(value = CmsConfigDef.Api.Rest.Cms.REST_CMS_SEO_OPTIMIZE)
public class CmsSeoOptimizeController extends BaseController {

	public static final String swaggerTag = "SEO搜索优化";

	@Autowired
	private CmsSeoOptimizeService cmsSeoOptimizeService;

	@AuthenticationAnnotation
	@RequestMapping(value = "/{seoOptimizeId}", method = RequestMethod.GET)
	@ApiOperation(value = "获取CMS-SEO搜索引擎优化", httpMethod = "GET", notes = "获取CMS站点-SEO搜索引擎优化通过ID", tags = swaggerTag)
	@RequestPlanAnnotation(title = "获取CMS-SEO搜索引擎优化", content = "获取CMS站点-SEO搜索引擎优化通过ID")
	public ResponseEntity<ControllerResult<CmsSeoOptimizeVo>> getSeoOptimize(
			@ApiParam(required = true, name = "seoOptimizeId", value = "-SEO搜索引擎优化ID") @PathVariable String seoOptimizeId) {
		try {
			if (CommonUtil.isEmpty(seoOptimizeId)) {
				return ControllerResult.failed(OperationStatus.LOAD_FAIL + ",SEO搜索引擎优化ID不能为空");
			}
			return ControllerResult.success(cmsSeoOptimizeService.getCmsSeoOptimize(seoOptimizeId),
					OperationStatus.LOAD_SUCCESSFUL);
		} catch (Exception e) {
			return ControllerResult.failed(e);
		}
	}

	@AuthenticationAnnotation
	@RequestMapping(method = RequestMethod.POST)
	@ApiOperation(value = "添加CMS站点-SEO搜索引擎优化", httpMethod = "POST", notes = "添加CMS站点-SEO搜索引擎优化", tags = swaggerTag)
	@RequestPlanAnnotation(title = "添加CMS站点-SEO搜索引擎优化", content = "添加CMS站点-SEO搜索引擎优化")
	public ResponseEntity<ControllerResult<String>> addSeoOptimize(
			@ApiParam(required = true, name = "body", value = "站点-SEO搜索引擎优化") @RequestBody(required = true) CmsSeoOptimizeVo seoOptimizeVo) {
		try {
			if (CommonUtil.isEmpty(seoOptimizeVo.getKeywords())) {
				return ControllerResult.failed(OperationStatus.ADD_FAIL + ",基本信息不完整");
			}
			return ControllerResult.success(cmsSeoOptimizeService.addCmsSeoOptimize(seoOptimizeVo, currentUserId()),
					OperationStatus.ADD_SUCCESSFUL);
		} catch (Exception e) {
			return ControllerResult.failed(e);
		}
	}

	@AuthenticationAnnotation
	@RequestMapping(value = "/{seoOptimizeId}", method = RequestMethod.PUT)
	@ApiOperation(value = "修改CMS-SEO搜索引擎优化", httpMethod = "PUT", notes = "修改CMS-SEO搜索引擎优化", tags = swaggerTag)
	@RequestPlanAnnotation(title = "修改CMS-SEO搜索引擎优化", content = "修改CMS-SEO搜索引擎优化")
	public ResponseEntity<ControllerResult<String>> updateSeoOptimize(
			@ApiParam(required = true, name = "body", value = "系统用户信息") @RequestBody(required = true) CmsSeoOptimizeVo seoOptimizeVo,
			@ApiParam(required = true, name = "seoOptimizeId", value = "系统用户ID") @PathVariable String seoOptimizeId) {
		try {
			if (CommonUtil.isEmpty(seoOptimizeVo.getKeywords(), seoOptimizeId)) {
				return ControllerResult.failed(OperationStatus.UPDATE_FAIL + ",基本信息不完整");
			}
			seoOptimizeVo.setId(seoOptimizeId);
			return ControllerResult.success(cmsSeoOptimizeService.updateCmsSeoOptimize(seoOptimizeVo, currentUserId()),
					OperationStatus.UPDATE_SUCCESSFUL);
		} catch (Exception e) {
			return ControllerResult.failed(e);
		}
	}

	@AuthenticationAnnotation
	@RequestMapping(value = "/{seoOptimizeId}", method = RequestMethod.DELETE)
	@ApiOperation(value = "删除CMS-SEO搜索引擎优化", httpMethod = "DELETE", notes = "删除CMS-SEO搜索引擎优化", tags = swaggerTag)
	@RequestPlanAnnotation(title = "删除CMS-SEO搜索引擎优化", content = "删除CMS-SEO搜索引擎优化")
	public ResponseEntity<ControllerResult<String>> deleteSeoOptimize(
			@ApiParam(required = true, name = "seoOptimizeId", value = "站点-SEO搜索引擎优化ID") @PathVariable String seoOptimizeId) {
		try {
			if (CommonUtil.isEmpty(seoOptimizeId)) {
				return ControllerResult.failed(OperationStatus.DELELETE_FAIL + ",站点联系方式ID不能为空");
			}
			CmsSeoOptimizeVo seoOptimizeVo = new CmsSeoOptimizeVo();
			{
				seoOptimizeVo.setId(seoOptimizeId);
			}
			return ControllerResult.success(cmsSeoOptimizeService.deleteCmsSeoOptimize(seoOptimizeVo, currentUserId()),
					OperationStatus.DELELETE_SUCCESSFUL);
		} catch (Exception e) {
			return ControllerResult.failed(e);
		}
	}

	@AuthenticationAnnotation
	@RequestMapping(value = "/{pageNumber}/{pageSize}", method = RequestMethod.GET)
	@ApiOperation(value = "获取CMS-SEO搜索引擎优化数据", httpMethod = "GET", notes = "获取CMS-SEO搜索引擎优化数据", tags = swaggerTag)
	@RequestPlanAnnotation(title = "获取CMS-SEO搜索引擎优化数据", content = "获取CMS-SEO搜索引擎优化数据")
	public ResponseEntity<ControllerResult<PageInfo<CmsSeoOptimizeVo>>> querySeoOptimize(
			@ApiParam(required = true, name = "pageNumber", value = "分页号(第一页值为1,小于1则默认返回第一页)") @PathVariable("pageNumber") Integer pageNumber,
			@ApiParam(required = true, name = "pageSize", value = "分页大小") @PathVariable("pageSize") Integer pageSize) {
		try {
			if (CommonUtil.isEmpty(pageNumber, pageSize)) {
				return ControllerResult.failed(OperationStatus.LOAD_FAIL + ",请求参数错误");
			}
			return ControllerResult.success(cmsSeoOptimizeService.queryCmsSeoOptimize(pageNumber, pageSize),
					OperationStatus.LOAD_SUCCESSFUL);
		} catch (Exception e) {
			return ControllerResult.failed(e);
		}
	}
}
